package subject_set.lc200;

/**
 * @author haomin
 * @date 2022/12/16 23:09
 **/
public class Num14 {
    class Solution {
        public String longestCommonPrefix(String[] strs) {
            String s = strs[0];
            for(int i = 1; i < strs.length; ++i) {
                int p = 0;
                while(p < s.length() && p < strs[i].length() && s.charAt(p) == strs[i].charAt(p)) p++;
                s = s.substring(0, p);
                if(s.length() == 0) return s;
            }
            return s;
        }
    }

    class Solution2 {
        public String longestCommonPrefix(String[] strs) {
            String s = strs[0];
            for(String str : strs) {
                while(!str.startsWith(s)) {
                    s = s.substring(0, s.length() - 1);
                }
                if(s.length() == 0) return s;
            }
            return s;
        }
    }
}